<?php
/**
 * Created by IntelliJ IDEA.
 * User: Administrator
 * Date: 2019/12/4
 * Time: 11:01
 */

namespace app\api\controller;


use app\api\ApiController;
use think\facade\Db;

class Search extends ApiController
{
    protected function initialize()
    {
    }

    public function index(){
        $search = $this->reqdata['search'];
        $res = $this->validate($this->reqdata,['search'=>'min:2']);
        if ($res!==true){
            $this->error($res);
        }
        $list = explode(' ',$search);
        $arr = [];
        foreach ($list as $v){
            $arr[] = [
                ['areaName', 'like', '%'.$v.'%'],
            ];
        }
        $db = Db::name('area')->where(function ($query) use($arr) {
            $query->whereOr($arr);
        })->select();

        $this->success($db);
    }
}
